//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;
using OpenLS.Drawing.Internals;

namespace OpenLS.Drawing
{
    internal class TableRow : IOfficeXmlSerializable
    {
        internal const string xmlName = "tr";
        private readonly List<TableCell> tc = new List<TableCell>();
        private OfficeArtExtensionList extLst;
        private double h;

        #region IOfficeXmlSerializable Members

        /// <summary>
        /// Generates an object from its XML representation
        /// </summary>
        /// <param name="context"></param>
        public void ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read(xmlName))
            {
                h = EmuConverter.FromEmu(c.GetInteger("h"));
                tc.Clear();
                tc.AddRange(c.ReadOptionalWhile<TableCell>(TableCell.xmlName));
                extLst = c.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }
        }

        /// <summary>
        /// Convert an object into its XML representation
        /// </summary>
        /// <param name="context"></param>
        public void WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write(xmlName))
            {
                c.SetInteger64("h", EmuConverter.ToEmu(h));
                c.WriteElements(tc);
                c.WriteOptionalElement(extLst);
            }
        }

        #endregion
    }
}